const mongoose = require('mongoose')
const User = mongoose.model('user')

//判断登录用户密码是否正确
export const checkPassword = async (username,password)=>{
    let match = false
    const user = await User.findOne({username})
    if(user){
        match = await user.comparePassword(password,user.password)
    }
    return {
        user,match
    }
}

//保存用户
export const addUser = async (userinfo)=>{
    const user = new User(userinfo)
    return await user.save()
}

//根据id查询用户
export const getUserById = async (id)=>{
   const user =  await User.findById(id)
   return user
}